import warnings

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
test1_boy = pd.read_excel(r'C:\Users\Jerry Peng\Desktop\培训学习\第五章\Matplotlib数据可视化\matplotlib作业\体测分数_男生.xls',
                          header=0)
test1_girl = pd.read_excel(r'C:\Users\Jerry Peng\Desktop\培训学习\第五章\Matplotlib数据可视化\matplotlib作业\体测分数_女生.xls',
                            header=0)
boy_1000 = pd.cut(test1_boy['男1000米跑分数'],bins=3,labels=['慢','中','快']).value_counts()
per=boy_1000/boy_1000.sum()
fig=plt.figure(figsize=(5,5), dpi=150)
plt.pie(boy_1000,labels=per.index,autopct='%0.2f%%',
        textprops = {'family':'Kaiti',  'fontsize':20})
#plt.show()
boy_yt = pd.cut(test1_boy['男引体分数'],bins=3,labels=['差','中','好']).value_counts()
per=boy_yt/boy_yt.sum()
fig=plt.figure(figsize=(5,5), dpi=150)
plt.pie(boy_yt,labels=per.index,autopct='%0.2f%%',
        textprops = {'family':'Kaiti',  'fontsize':20})


plt.hist(test1_girl['女800米跑分数'],bins = 4,rwidth= 0.5)
plt.xticks([25,50,75,100])
plt.hist(test1_girl['女跳远分数'],bins = 4,rwidth= 0.5)
plt.xticks([25,50,75,100])
boy_BMI = pd.cut(test1_boy['BMI'].round(1),#保留一位小数
                 bins = [0,16.4,23.2,26.3,100],
                 labels=['低体重','正常','超重','肥胖']).value_counts()
boy_BMI_percent = boy_BMI/boy_BMI.sum()
girl_BMI = pd.cut(test1_girl['BMI'].round(1),#保留一位小数
                 bins = [0,16.4,22.7,25.2,100],
                 labels=['低体重','正常','超重','肥胖']).value_counts()
girl_BMI_percent = girl_BMI/girl_BMI.sum()
plt.figure(figsize=(9,9))
plt.pie(girl_BMI_percent,radius=1,
        autopct='%0.2f%%',
        pctdistance=0.85,
        labels = ['低体重','正常','超重','肥胖'],
        wedgeprops={'linewidth':5,# 间隔的宽度
                    'width':0.3, # 饼图的宽度
                    'edgecolor':'white'},# 间隔的颜色
        textprops={'family':'Kaiti','fontsize':18})
plt.rcParams['font.family'] = 'Kaiti'
plt.pie(boy_BMI_percent,
        radius=0.7,
        autopct='%0.2f%%',
        pctdistance=0.55,
        wedgeprops={'linewidth':5,# 间隔的宽度
                    'width':0.7, # 饼图的宽度
                    'edgecolor':'white'})# 间隔的颜色

plt.legend(['低体重','正常','超重','肥胖'],title = 'BMI')
plt.show()